package offer.twoPointers;

import java.util.ArrayList;

/**
 * @author DengYuan2
 * @create 2021-02-19 21:57
 */
public class n_57_1{
    public static void main(String[] args) {
        n_57_1 n = new n_57_1();
        int[] arr={1,2,4,7,11,14};
        int sum=15;
        ArrayList<Integer> res = n.FindNumbersWithSum(arr, sum);
        System.out.println(res);

    }

    public ArrayList<Integer> FindNumbersWithSum(int [] array, int sum) {
        ArrayList<Integer> list = new ArrayList<>();
        int left = 0;
        int right = array.length-1;
        while (left<right){
            int l=array[left];
            int r = array[right];
            int s = l+r;
            if (s>sum){
                right--;
            }else if (s<sum){
                left++;
            }else {
                //todo 不要被题目误导，肯定是最外层的最小哇，所以找到之后不用再往里找啦
                list.add(l);
                list.add(r);
                break;
            }
        }

        return list;
    }
}
